<template>
  <div class="fillcontain">
    <head-top></head-top>
    <div class="table_container">
        <!-- <el-row :gutter="20">
            <el-col :span="10" :offset="3" >
           <el-input placeholder="请输入内容" v-model="input3" class="input-with-select">
                <el-select style="width:130px" v-model="select" slot="prepend" placeholder="请选择">
                    <el-option v-for="item in selectOptions"
                    :key="item.value" 
                    :label="item.lable"
                     :value="item.value"></el-option>
                </el-select>
                <el-button @click="search" slot="append" icon="el-icon-search" >搜索</el-button>
            </el-input>
          </el-col>

        </el-row> -->
      <el-table :data="tableData" highlight-current-row style="width: 100%">
        <el-table-column type="index"  width="50" label="序号"> </el-table-column>
        <el-table-column property="userName" label="评论人" width="200">
        </el-table-column>
        <el-table-column property="scenName" label="景区" width="200">
        </el-table-column>
        <el-table-column property="grade" label="等级" width="50"> </el-table-column>
        <el-table-column property="content"  label="评论内容" width="200"> 
          <template slot-scope="scope">
            <el-input type="textarea" :rows="2" disabled :value="scope.row.content"/>
          </template> 
        </el-table-column>
        <el-table-column property="time" label="评论时间" width="200"> </el-table-column>
        <el-table-column label="图片">
          <template slot-scope="scope">
            <img v-for="item in scope.row.pics" :key="item.id" :src="item.url" width="30" height="30" />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="Pagination" style="text-align: left; margin-top: 10px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="10"
          layout="total, prev, pager, next"
          :total="count"
        >
        </el-pagination>
      </div>
       <!-- 修改提示框 -->
     <el-dialog title="修改评论信息" v-model="dialogFormVisible">
        <div slot="footer">
          <el-form :model="selectTable">
           
            <el-form-item label="ID" label-width="100px">
              <el-input disabled v-model="selectTable.id"></el-input>
            </el-form-item>
            <el-form-item label="内容" label-width="100px">
              <el-input  type="textarea" :maxlength="200" show-word-limit v-model="selectTable.content"></el-input>
            </el-form-item>
  
            
     
          </el-form>
         
                <div v-for="item in selectTable.pics" :key="item.id" :span="6">
                  <el-image :src="item.url"
                  style="width: 100px; height: 100px"
                  fit="fit"/>
                </div>
                 
       
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="update">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import headTop from "../components/headTop";
import axios from "axios";
import { getCommentByPage,deleteCommentById} from "@/api/scenery";


export default {
  data() {
    return {
      tableData: [
        {
          nickName: "2016-05-02",
          phNum: "王小虎",
          province: "江西",
          city: "南昌",
          avatar:
            "https://thirdwx.qlogo.cn/mmopen/vi_32/VMWTEwwcHqfCD56TkJiaVcIoNm4QX1mxwhwts4kWBe6rrNsG75csjE1x4ibmSH1BNLG58gWj9RyQLhaunubapfZw/132",
          name: "",
          idNum: "",
        },
      ],
      list: [],
      currentRow: null,
      offset: 0,
      limit: 10,
      count: 0,
      currentPage: 1,
      dialogFormVisible:false,
      selectTable:{},
      input3:'',
      select:1,
      status:-1,
      selectOptions: [{
        lable:"ID",value:"1"
      },{
        lable:"用户名",value:"2"
      },{
        lable:"电话",value:"3"
      }]
    };
  },
  components: {
    headTop,
  },
  created() {
    this.initData(); 
    this.select = this.selectOptions[0].value
 
  },
  methods: {
    async initData() {
      try {
 

        this.getList();
      } catch (err) {
        console.log("获取数据失败", err);
      }
    },
    handleSizeChange(val) {
      this.limit = val;
      console.log(`每页 ${val} 条`);
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.offset = (val - 1) * this.limit;
      console.log(this.currentPage, this.offset);
      this.getList();
    },
    async getList() {
      console.log(this.currentPage,this.limit);
      const res = await getCommentByPage(this.currentPage,this.limit);
      if(res&&res.code>=0){
        this.tableData  = res.data.rows;
        this.count = res.data.totalCount
      }else{
        console.log(res.message);
      }
      

    },

    //根据id删除图片
    async deletePic(id){
      if(!id)return;

    },
    async handleDelete(index, row){
      let id = row.id
       await   deleteCommentById(id)
       this.$message.success('删除成功');
       this.getList()
      
    },
    async handleEdit(index, row) {

    //index 就是第几个，可以从scenery直接取
      console.log("handleEdit(index, row)", index, row);
      this.selectTable= row
      this.dialogFormVisible = true;
    }
    },

    async search(){
        console.log("input3",this.input3);
        console.log("select",this.select);
    },
    //跟新用户信息
    async  update(){
       
    }
  }

</script>

<style lang="less">
@import "../style/mixin";
.table_container {
  padding: 20px;
}
</style>
